﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;

namespace VodafoneContracts
{
    public enum VodafoneContractType
    {
        Undefined = 1,
        OnlyCredit = 2,
        MobileInternet = 3,
        SmartZeroLimits = 4
    }
    public static class Utils
    {
        public static List<String> TypeNames = new List<string>(){
            "Undefined",
            "Vodafone Credit",
            "Mobile Internet",
            "Smart Zero Limits"
        };
        public static List<VodafoneContractType> Types = new List<VodafoneContractType>(){
            VodafoneContractType.Undefined,
            VodafoneContractType.OnlyCredit,
            VodafoneContractType.MobileInternet,
            VodafoneContractType.SmartZeroLimits
        };
        public static string GetTypeDesc(VodafoneContractType type)
        {
            for (int i = 0; i < Types.Count; i++)
                if (Types[i] == type)
                    return TypeNames[i];
            return TypeNames[0];
        }

        public static VodafoneContractType GetType(string name)
        {
            for (int i = 0; i < Types.Count; i++)
                if (TypeNames[i] == name)
                    return Types[i];
            return VodafoneContractType.Undefined;
        }
        public static string GetUpdateLiveTileArgs(VodafoneResult result, VodafoneContractType type, string username, string password, string number, bool showDate)
        {
            /*

            username=" +
                currentAccount.username
                + "&password=" +
                currentAccount.password
                + "&number=" +
                currentAccount.number
                + (currentAccount.showCredit ? "&euro=" + credit : "")
                + (currentAccount.showMobileInternet ? "&traffic=" + internet : "")
                + (currentAccount.showSmartZeroLimits ? "&traffic=" + internet : "")
                + (currentAccount.showDate ? "&date=1" : "");
            
            */
            string s = "username=" +
                username
                + "&password=" +
                password
                + "&number=" +
                number
                + "&date=";
            if (showDate)
                s += "1";

            switch (type)
            {
                case VodafoneContractType.OnlyCredit:
                    s += "&euro=" + result.credit;
                    break;
                case VodafoneContractType.MobileInternet:
                case VodafoneContractType.SmartZeroLimits:
                    s += "&euro=" + result.credit + "&traffic=" + result.traffic;
                    break;
                default:
                    s = "";
                    break;
            }

            return s;
        }

        public static string GetManageUrisArgs(VodafoneContractType type, string username, string password, string number, bool isFirstNumber, bool showDate, string id, bool enabled)
        {
            return GetManageUrisArgs(type, username, password, number, isFirstNumber, showDate, id, "", "", enabled);
        }
        public static string GetManageUrisArgs(VodafoneContractType type, string username, string password, string number, bool isFirstNumber, bool showDate, string id, string tileUri, string toastUri, bool enabled)
        {
            /*
            http://fboscari.altervista.org/Vodafone/ManageUris.php?
             * username=gmrfcb&
             * password=gmrfcb&
             * number=3477566391&
             * contract=Mobile Internet&
             * isFirstNumber=1&
             * showDate=1&  
             * uri=1
             */
            string s = "username=" +
                username
                + "&password=" +
                password
                + "&number=" +
                number;
            if (showDate)
                s += "&showDate=1";
            if(isFirstNumber)
                s += "&isFirstNumber=1";
            s += "&contract=" +
                GetTypeDesc(type);
            s += "&tileUri=" +
                tileUri;
            s += "&toastUri=" +
                toastUri;
            s += "&id=" +
                id;
            if (!enabled)
                s += "&enabled=0";

            return s;
        }

    }
}
